package com.itboye.lottery.activity.user;

import android.view.View;

import android.widget.Button;
import android.widget.EditText;

import com.itboye.lottery.base.BaseActivity;
import com.itboye.lottery.R;
import com.itboye.lottery.alert.ByAlert;
import com.itboye.lottery.presenter.UserPresenter;
import com.itboye.lottery.retrofit.ResponseCallback;

import org.jetbrains.annotations.NotNull;

public class AdviceActivity extends BaseActivity implements ResponseCallback {

    EditText ed_advice;
    Button btn_submit;
    UserPresenter userPresenter;

    @Override
    protected void initData() {
        userPresenter = new UserPresenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_advice;
    }

    @Override
    public void onClick(View view) {
        if (view == btn_submit) {
            String content = ed_advice.getText().toString();
            if (content.isEmpty()) {
                ByAlert.alert("请输入意见或者建议");
                return;
            }
            if (content.length() > 200) {
                ByAlert.alert("输入内容过长");
                return;
            }
            userPresenter.feedback(content);
        }
    }

    @Override
    public void success(@NotNull Object o, @NotNull String requestSuccessType) {
        ByAlert.alert("提交成功");
        finish();
    }

    @Override
    public void fail(int code, @NotNull Object msg, @NotNull String requestErrorType) {
        ByAlert.alert(msg);
    }
}
